package com.cb.wxy.controller;

import com.cb.service.*;
import com.cb.wxy.pojo.CouoponsUser;
import com.jia.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/combo")
public class ComboController {
    @Autowired
    private CombiTimeService combiTimeService;
    @Autowired
    private ComboMidService comboMidService;
    @Autowired
    private CouoponsUserService couoponsUserService;
    @Autowired
    private ActivityService activityService;

    @Autowired
    private ComboVService comboVService;
//    实现用户购买套餐功能 需考虑使用优惠卷情况
//    1.拿到用户id
//    2.拿到优惠卷id
//    3.判断优惠卷是否可用
//    4.判断优惠卷是否可用
    @GetMapping("/buyTcs")
    public Result buyCombo(Integer id,Integer money){
        System.out.println(id);
        System.out.println(money);
        boolean buy = this.comboMidService.buy(id, money);
        return buy ? Result.build(true, 200, "购买成功") : Result.build(false, 400, "购买失败");
    }
//    实现用户续费套餐功能需考虑使用卡券情况
    @RequestMapping("/renew")
    public void renewCombo(){
    }
//    实现购买套餐系统算法 注意是否改装车选项的设计
    @RequestMapping("/system")
    public void buyComboSystem(){
    }

    /**
     * 查询套餐信息
     */
    @GetMapping("/getComboInfo")
    public void getComboInfo(){
    }
    /**
     * 查询卡券信息
     */
    @GetMapping("/getCardInfo")
    public void getCardInfo(){
    }
    /**
     * 查询套餐时长
     */
    @GetMapping("/getComboTime")
    public Result getComboTime(){
        return Result.build(combiTimeService.list(), 200, "查询成功");
    }
    /**
     * 查询电压
     */
    @GetMapping("/getVoltage")
    public Result getVoltage(){
        return Result.build(comboVService.list(), 200, "查询成功");
    }
    /**
     * 查询电流
     */
    @GetMapping("/getMoney")
    public Result getMoney(Integer cid,Integer tid,Integer vid,Integer state){
        Integer money = comboMidService.getMoney(cid,tid,vid,state);
        return Result.build(money, 200, "查询成功");
    }
    @PutMapping("/addXtt")
    public Result addXtt(Integer id){
          boolean ids =  comboMidService.getId(id);
        return Result.build(ids, 200, "查询成功");
    }
    @GetMapping("/getUidCid")
    public Result getUidCid(Integer id){
        List<CouoponsUser> uidCid = couoponsUserService.getUidCid(id);
        return Result.build(uidCid, 200, "查询成功");
    }
    @GetMapping("/getUidCidById")
    public Result getUidCidById(Integer id,Integer cid){
        Integer uidCid = couoponsUserService.getUidCidByid(id,cid);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>."+uidCid);
        return uidCid!=0?Result.build(uidCid, 200, "查询成功"):Result.build(false, 400, "查询失败");
    }
    @PutMapping("/TOMyinte")
    public Result TOMyinte(Integer id,Integer integral){
        this.comboMidService.updateByIdByinted(id,integral);
        return Result.build("ok", 200, "查询成功");
    }
    @PostMapping("/addMyinte")
    public Result addMyinte(Integer cid,Integer uid){
        return Result.build( this.couoponsUserService.addMyinte(cid,uid), 200, "查询成功");
    }
    @GetMapping("/getActivity")
    public Result getActivity(){
        return Result.build(activityService.list(), 200, "查询成功");
    }
}
